package com.tth.learn.addproperties.java1;

import org.junit.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 网络编程--通信要素1：IP和端口号
 * @Author tth
 * @Date 2022/12/28 10:10
 */
public class InetAddressTest {

    @Test
    public void test1() {
        try {
            InetAddress inte1 = InetAddress.getByName("192.168.23.37");
            System.out.println(inte1);

            InetAddress inte2 = InetAddress.getByName("www.baidu.com");
            System.out.println(inte2);

            InetAddress inet3 = InetAddress.getLocalHost();
            System.out.println(inet3);

            String hostName = inet3.getHostName();
            System.out.println(hostName);

            String hostAddress = inet3.getHostAddress();
            System.out.println(hostAddress);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
